home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / JOYSTICK.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  7KB  |  300 lines

  1. #ifndef _LINUX_JOYSTICK_H
  2. #define _LINUX_JOYSTICK_H
  3.  
  4. /*
  5.  * /usr/include/linux/joystick.h  Version 1.2
  6.  *
  7.  * Copyright (C) 1996-1998 Vojtech Pavlik
  8.  */
  9.  
  10. /*
  11.  * This program is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or 
  14.  * (at your option) any later version.
  15.  * 
  16.  * This program is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24.  * 
  25.  * Should you need to contact me, the author, you can do so either by
  26.  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  27.  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
  28.  */
  29.  
  30. #include <asm/types.h>
  31. #include <linux/module.h>
  32.  
  33. /*
  34.  * Version
  35.  */
  36.  
  37. #define JS_VERSION        0x01020d
  38.  
  39. /*
  40.  * Types and constants for reading from /dev/js
  41.  */
  42.  
  43. #define JS_EVENT_BUTTON        0x01    /* button pressed/released */
  44. #define JS_EVENT_AXIS        0x02    /* joystick moved */
  45. #define JS_EVENT_INIT        0x80    /* initial state of device */
  46.  
  47. struct js_event {
  48.     __u32 time;    /* event timestamp in miliseconds */
  49.     __s16 value;    /* value */
  50.     __u8 type;    /* event type */
  51.     __u8 number;    /* axis/button number */
  52. };
  53.  
  54. /*
  55.  * IOCTL commands for joystick driver
  56.  */
  57.  
  58. #define JSIOCGVERSION        _IOR('j', 0x01, __u32)            /* get driver version */
  59.  
  60. #define JSIOCGAXES        _IOR('j', 0x11, __u8)            /* get number of axes */
  61. #define JSIOCGBUTTONS        _IOR('j', 0x12, __u8)            /* get number of buttons */
  62. #define JSIOCGNAME(len)        _IOC(_IOC_READ, 'j', 0x13, len)         /* get identifier string */
  63.  
  64. #define JSIOCSCORR        _IOW('j', 0x21, struct js_corr)        /* set correction values */
  65. #define JSIOCGCORR        _IOR('j', 0x22, struct js_corr)        /* get correction values */
  66.  
  67. /*
  68.  * Types and constants for get/set correction
  69.  */
  70.  
  71. #define JS_CORR_NONE        0x00    /* returns raw values */
  72. #define JS_CORR_BROKEN        0x01    /* broken line */
  73.  
  74. struct js_corr {
  75.     __s32 coef[8];
  76.     __s16 prec;
  77.     __u16 type;
  78. };
  79.  
  80. /*
  81.  * v0.x compatibility definitions
  82.  */
  83.  
  84. #define JS_RETURN        sizeof(struct JS_DATA_TYPE)
  85. #define JS_TRUE            1
  86. #define JS_FALSE        0
  87. #define JS_X_0            0x01
  88. #define JS_Y_0            0x02
  89. #define JS_X_1            0x04
  90. #define JS_Y_1            0x08
  91. #define JS_MAX            2
  92.  
  93. #define JS_DEF_TIMEOUT        0x1300
  94. #define JS_DEF_CORR        0
  95. #define JS_DEF_TIMELIMIT    10L
  96.  
  97. #define JS_SET_CAL        1
  98. #define JS_GET_CAL        2
  99. #define JS_SET_TIMEOUT        3
  100. #define JS_GET_TIMEOUT        4
  101. #define JS_SET_TIMELIMIT    5
  102. #define JS_GET_TIMELIMIT    6
  103. #define JS_GET_ALL        7
  104. #define JS_SET_ALL        8
  105.  
  106. struct JS_DATA_TYPE {
  107.     int buttons;
  108.     int x;
  109.     int y;
  110. };
  111.  
  112. struct JS_DATA_SAVE_TYPE {
  113.     int JS_TIMEOUT;
  114.     int BUSY;
  115.     long JS_EXPIRETIME;
  116.     long JS_TIMELIMIT;
  117.     struct JS_DATA_TYPE JS_SAVE;
  118.     struct JS_DATA_TYPE JS_CORR;
  119. };
  120.  
  121. /*
  122.  * Internal definitions
  123.  */
  124.  
  125. #ifdef __KERNEL__
  126.  
  127. #define JS_BUFF_SIZE        64        /* output buffer size */
  128.  
  129. #include <linux/version.h>
  130.  
  131. #ifndef KERNEL_VERSION
  132. #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
  133. #endif
  134.  
  135. #ifndef LINUX_VERSION_CODE
  136. #error "You need to use at least 2.0 Linux kernel."
  137. #endif
  138.  
  139. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0)
  140. #error "You need to use at least 2.0 Linux kernel."
  141. #endif
  142.  
  143. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
  144. #define JS_HAS_RDTSC (current_cpu_data.x86_capability & 0x10)
  145. #include <linux/init.h>
  146. #else
  147. #ifdef MODULE
  148. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,0,35)
  149. #define JS_HAS_RDTSC (x86_capability & 0x10)
  150. #else
  151. #define JS_HAS_RDTSC 0
  152. #endif
  153. #else
  154. #define JS_HAS_RDTSC (x86_capability & 0x10)
  155. #endif
  156. #define __initdata
  157. #define __init
  158. #define __cli cli
  159. #define __save_flags(flags) save_flags(flags)
  160. #define __restore_flags(flags)    restore_flags(flags)
  161. #define spin_lock_irqsave(x, flags) do { save_flags(flags); cli(); } while (0)
  162. #define spin_unlock_irqrestore(x, flags) restore_flags(flags)
  163. #define spin_lock_init(x) do { } while (0)
  164. typedef struct { int something; } spinlock_t;
  165. #define SPIN_LOCK_UNLOCKED { 0 }
  166. #define MODULE_AUTHOR(x)
  167. #define MODULE_PARM(x,y)
  168. #define MODULE_SUPPORTED_DEVICE(x)
  169. #define signal_pending(x) (((x)->signal) & ~((x)->blocked))
  170. #endif
  171.  
  172. /*
  173.  * Parport stuff
  174.  */
  175.  
  176. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
  177. #define USE_PARPORT
  178. #endif
  179.  
  180. #ifdef USE_PARPORT
  181. #include <linux/parport.h>
  182. #define JS_PAR_DATA_IN(y)    parport_read_data(y->port)
  183. #define JS_PAR_DATA_OUT(x,y)    parport_write_data(y->port, x)
  184. #define JS_PAR_STATUS(y)    parport_read_status(y->port)
  185. #define JS_PAR_CTRL_IN(y)    parport_read_control(y->port)
  186. #define JS_PAR_CTRL_OUT(x,y)    parport_write_control(y->port, x)
  187. #define JS_PAR_ECTRL_OUT(x,y)    parport_write_econtrol(y->port, x)
  188. #else
  189. #define JS_PAR_DATA_IN(y)    inb(y)
  190. #define JS_PAR_DATA_OUT(x,y)    outb(x,y)
  191. #define JS_PAR_STATUS(y)    inb(y+1)
  192. #define JS_PAR_CTRL_IN(y)    inb(y+2)
  193. #define JS_PAR_CTRL_OUT(x,y)    outb(x,y+2)
  194. #define JS_PAR_ECTRL_OUT(x,y)    outb(x,y+0x402)
  195. #endif
  196.  
  197. #define JS_PAR_STATUS_INVERT    (0x80)
  198. #define JS_PAR_CTRL_INVERT    (0x04)
  199.  
  200. /*
  201.  * Internal types
  202.  */
  203.  
  204. struct js_dev;
  205.  
  206. typedef int (*js_read_func)(void *info, int **axes, int **buttons);
  207. typedef unsigned int (*js_time_func)(void);
  208. typedef int (*js_delta_func)(unsigned int x, unsigned int y);
  209. typedef int (*js_ops_func)(struct js_dev *dev);
  210.  
  211. struct js_data {
  212.     int *axes;
  213.     int *buttons;
  214. };
  215.  
  216. struct js_dev {
  217.     struct js_dev *next;
  218.     struct js_list *list;
  219.     struct js_port *port;
  220.     struct wait_queue *wait;
  221.     struct js_data cur;
  222.     struct js_data new;
  223.     struct js_corr *corr;
  224.     struct js_event buff[JS_BUFF_SIZE];
  225.     js_ops_func open;
  226.     js_ops_func close;
  227.     int ahead;
  228.     int bhead;
  229.     int tail;
  230.     int num_axes;
  231.     int num_buttons;
  232.     char *name;
  233. };
  234.  
  235. struct js_list {
  236.     struct js_list *next;
  237.     struct js_dev *dev;
  238.     int tail;
  239.     int startup;
  240. };
  241.  
  242. struct js_port {
  243.     struct js_port *next;
  244.     struct js_port *prev;
  245.     js_read_func read;
  246.     struct js_dev **devs;
  247.     int **axes;
  248.     int **buttons;
  249.     struct js_corr **corr;
  250.     void *info;
  251.     int ndevs;
  252. };
  253.  
  254. /*
  255.  * Sub-module interface
  256.  */
  257.  
  258. extern unsigned int js_time_speed;
  259. extern js_time_func js_get_time;
  260. extern js_delta_func js_delta;
  261.  
  262. extern unsigned int js_time_speed_a;
  263. extern js_time_func js_get_time_a;
  264. extern js_delta_func js_delta_a;
  265.  
  266. extern struct js_port *js_register_port(struct js_port *port, void *info,
  267.     int devs, int infos, js_read_func read);
  268. extern struct js_port *js_unregister_port(struct js_port *port);
  269.  
  270. extern int js_register_device(struct js_port *port, int number, int axes,
  271.     int buttons, char *name, js_ops_func open, js_ops_func close);
  272. extern void js_unregister_device(struct js_dev *dev);
  273.  
  274. /*
  275.  * Kernel interface
  276.  */
  277.  
  278. extern int js_init(void);
  279. extern int js_am_init(void);
  280. extern int js_an_init(void);
  281. extern int js_as_init(void);
  282. extern int js_console_init(void);
  283. extern int js_db9_init(void);
  284. extern int js_gr_init(void);
  285. extern int js_l4_init(void);
  286. extern int js_lt_init(void);
  287. extern int js_sw_init(void);
  288. extern int js_tm_init(void);
  289.  
  290. extern void js_am_setup(char *str, int *ints);
  291. extern void js_an_setup(char *str, int *ints);
  292. extern void js_as_setup(char *str, int *ints);
  293. extern void js_console_setup(char *str, int *ints);
  294. extern void js_db9_setup(char *str, int *ints);
  295. extern void js_l4_setup(char *str, int *ints);
  296.  
  297. #endif /* __KERNEL__ */
  298.  
  299. #endif /* _LINUX_JOYSTICK_H */
  300.